package com.ruoyi.wetest.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wetest.domain.WetestProjects;
import com.ruoyi.wetest.service.IWetestProjectsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 压测项目Controller
 * 
 * @author ruoyi
 * @date 2024-04-30
 */
@RestController
@RequestMapping("/wetest/projects")
public class WetestProjectsController extends BaseController
{
    @Autowired
    private IWetestProjectsService wetestProjectsService;

    /**
     * 查询压测项目列表
     */
    @PreAuthorize("@ss.hasPermi('wetest:projects:list')")
    @GetMapping("/list")
    public TableDataInfo list(WetestProjects wetestProjects)
    {
        startPage();
        List<WetestProjects> list = wetestProjectsService.selectWetestProjectsList(wetestProjects);
        return getDataTable(list);
    }

    /**
     * 导出压测项目列表
     */
    @PreAuthorize("@ss.hasPermi('wetest:projects:export')")
    @Log(title = "压测项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WetestProjects wetestProjects)
    {
        List<WetestProjects> list = wetestProjectsService.selectWetestProjectsList(wetestProjects);
        ExcelUtil<WetestProjects> util = new ExcelUtil<WetestProjects>(WetestProjects.class);
        util.exportExcel(response, list, "压测项目数据");
    }

    /**
     * 获取压测项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('wetest:projects:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") String projectId)
    {
        return success(wetestProjectsService.selectWetestProjectsByProjectId(projectId));
    }

    /**
     * 新增压测项目
     */
    @PreAuthorize("@ss.hasPermi('wetest:projects:add')")
    @Log(title = "压测项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WetestProjects wetestProjects)
    {
        return toAjax(wetestProjectsService.insertWetestProjects(wetestProjects));
    }

    /**
     * 修改压测项目
     */
    @PreAuthorize("@ss.hasPermi('wetest:projects:edit')")
    @Log(title = "压测项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WetestProjects wetestProjects)
    {
        return toAjax(wetestProjectsService.updateWetestProjects(wetestProjects));
    }

    /**
     * 删除压测项目
     */
    @PreAuthorize("@ss.hasPermi('wetest:projects:remove')")
    @Log(title = "压测项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable String[] projectIds)
    {
        return toAjax(wetestProjectsService.deleteWetestProjectsByProjectIds(projectIds));
    }
}
